// logs.js
const {getcartapi,getcartgoosapi,goodsapi} = require('../../HTTP/api')

Page({
  data: {
    myId:'',
    leftarr:[],
    rightarr:[],
    newGoods:[],
  },
  async onShow(){
    // 左侧数据
    const res = await getcartapi()
    // console.log(res);
    this.setData({
      leftarr:res.data
    })

    // 右侧数据
    const resa = await getcartgoosapi()
    console.log(resa);
    this.setData({
      rightarr:resa.data.result
    })
  },
  add(e){
    let token = wx.getStorageSync('token')
    console.log('token::', token);
    this.setData({
      id: e.currentTarget.dataset.id
    })
    console.log(this.data.id);
    goodsapi({
      goodsId: this.data.id,
      token: token,
      number: this.data.Number
    }).then((res) => {
      console.log(res);
      wx.showToast({
        title: '加入购物车',
        icon: 'success'
      })
    })
  },
 
  over(e){
    console.log(e.currentTarget.dataset);
    let {id} = e.currentTarget.dataset
    this.setData({
      myId: id
    })
    let uu = this.data.rightarr.filter(item => item.categoryId == this.data.myId)
    console.log(uu);
    this.setData({
      newGoods: uu
    })
  },
  taozhuan(e){
    // console.log(e.currentTarget.dataset);
    let {id} = e.currentTarget.dataset
    wx.navigateTo({
      url: `/pages/xiaoqing/xiaoqing?id=${id}`,
    })
  },
})
